<%@page import="java.util.List"%>
<%@page import="springapp.web.data.VideoFile"%>
<%
    List<VideoFile> files = (List<VideoFile>) request.getAttribute("videos");
    if(files==null){
        throw new RuntimeException("You forget to provide 'videos' attribute for movielist.jsp");
    }
    int rowCount = files.size() / 4;
%>
<table style="width:100%;height:100%;padding-top: 10px;" >
    <%
        int imageIndex = 0;
        for (int i = 0; i < rowCount; i++) {
            out.println("<tr>");
            int columnCount = files.size() - i * 4;
            if (columnCount > 4) {
                columnCount = 4;
            }

            for (int j = 0; j < columnCount; j++, imageIndex++) {
                VideoFile video = files.get(imageIndex);
    %>
    <td style="text-align:center;padding-top: 20px;">
        <a href="/app/showVideo/<%=video.getId()%>.html">
            <div>
                <img src="/<%=video.getPicturesPath()%>f1.jpg" style="max-width: 200px; max-height: 200px;"/>
                <div>
                    <%=video.getTitle()%>
                </div>
            </div>
        </a>
    </td>
    <%
            }
            out.println("</tr>");
        }
    %>
</table>